<%@ page language="java" import="java.util.*, com.zjut.zs.util.tools.*,com.zjut.zs.userinfo.manager.*, com.zjut.zs.userinfo.dao.*,
com.zjut.zs.user.manager.*, com.zjut.zs.user.dao.*,com.zjut.an.util.tools.*,com.zjut.an.util.system.*" pageEncoding="utf-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
  	<!--顶部-->
	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="index.jsp">首页</a></li>
    <li><a href="#">注册</a></li>
    </ul>
    </div>
    
<form id="ff" name="add" role="form" class="form-horizontal" action="javascript:submitForm();" method="post"> 
    <div class="formbody">
    
    <div class="formtitle"><span>注册信息</span></div>
    
    <ul class="forminfo">
    <li><label>身份证号<b>*</b></label><input id="usIdcard" name="usIdcard" type="text" class="dfinput"  placeholder="身份证号" required data-rule-idCard="true" data-msg-required="不能为空" data-msg-idCard="请输入身份证号" value=""/><i></i></li>
    <li><label>邮箱<b>*</b></label><input id="usEmail" name="usEmail" type="text" class="dfinput"  placeholder="请输入email地址" required data-rule-email="true" data-msg-required="请输入email地址" data-msg-email="请输入正确的email地址"/><i>*请填写注册时的邮箱</i></li>
    <li><label>验证码<b>*</b></label>
	    	<input type="text" id="rand" name="rand" class="sfinput"/>
	    	<i><img style="cursor:pointer;width:60px;height:26px;" alt="" onclick="changeValidateCode()" ver_colorofnoisepoint="#888888"   id="JD_Verification1" src="../getValidateImage.action"></i>
	</li>
    <li><label>&nbsp;</label><button type="submit" class="btn btn-primary btn-sm">发送密码重置邮件</button>  </li>
    <li id="message"></li>
    </ul>
    
    
    </div>
 </form>
 

</body>
	
<script src="../plugins/assets/plugins/jquery-3.5.1.min.js" type="text/javascript"></script> 
<script src="../plugins/assets/plugins/jquery-validation-1.14.0/dist/jquery.validate.js" type="text/javascript"></script>
<script src="../plugins/assets/plugins/jquery-validation-1.14.0/dist/jquery.metadata.js" type="text/javascript"></script>
<script src="js/formvalidate.js" type="text/javascript"></script>
	<script type="text/javascript">  
		function submitForm() {
			//$("#ff").validate({ 
				var jsonString = JSON.stringify(serializeToJSON('#ff'));
				//console.log(jsonString);
				ajaxSubmitForm(jsonString);
			//})			
		}

		function serializeToJSON(formname) {
			var serializeObj=serializeForm($(formname));  
			//console.info(serializeObj);
		    return serializeObj;   
		}

		function serializeForm(form) { /* 将form表单内的元素序列化为对象，扩展Jquery的一个方法 */
			var o = {};
			$.each(form.serializeArray(), function(index) {
				if (o[this['name']]) {
					o[this['name']] = o[this['name']] + "," + this['value'];
				} else {
					o[this['name']] = this['value'];
				}
			});
			return o;
		}
		
		function ajaxSubmitForm(jsonString) {
			//console.log(jsonString);
			$.ajax({
		    	cache: false,
		    	type: "POST",
		        url:"../sendPassword.action?randnum="+Math.floor(Math.random()*1000000),
		        data:{rowstr:jsonString},// 你的formid
		        async: false,
		        error: function(request) {
		        	alert("网络有误");
		        },
		        success: function(data) {
		        	//console.log(data);
		        	if(data.message=="success"){
		            	window.location = './message.jsp?message=系统已经向您的注册邮箱发送了一封重置密码邮件，请登陆您的邮箱查阅'; ///当用ajax访问 时候成功的时候就自动的跳转过去
		        	} else if(data.message=="randfailed"){
		            	$("#message").html("验证码错误！");
		        		alert("验证码错误！");
		        		changeValidateCode();
		        	} else if(data.message=="emailfailed"){
		            	$("#message").html("身份证号或者邮箱不符，请重新填写！");
		        		changeValidateCode();
		        	} else {
		        		$("#message").html("发送邮件失败，请过会再试！");
		        		//alert("登陆失败，用户名或密码错误！");
		        		changeValidateCode();
		        	}
		        }
		    });
		}
		
		function changeValidateCode() {    
        	//这和浏览器的缓存机制有关系，也可以把页面设置为不缓存，这样就不用这个参数了。"nocache="+new Date().getTime()   
        	document.getElementById("JD_Verification1").src=document.getElementById("JD_Verification1").src + "?nocache="+new Date().getTime();    
               
 		} 
	</script>
</html>